package com.xujiakai.car.maintain.domain.entity;

import com.xujiakai.car.maintain.application.service.impl.BaseDataManageService;
import com.xujiakai.car.maintain.infrastructure.mapper.DaoFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class Projcategory {
    private Integer id;

    private String numbering;

    private String projcatenum;

    private String projname;

    private String catflag;

    @Resource
    private DaoFactory daoFactory;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNumbering() {
        return numbering;
    }

    public void setNumbering(String numbering) {
        this.numbering = numbering == null ? null : numbering.trim();
    }

    public String getProjcatenum() {
        return projcatenum;
    }

    public void setProjcatenum(String projcatenum) {
        this.projcatenum = projcatenum == null ? null : projcatenum.trim();
    }

    public String getProjname() {
        return projname;
    }

    public void setProjname(String projname) {
        this.projname = projname == null ? null : projname.trim();
    }

    public String getCatflag() {
        return catflag;
    }

    public void setCatflag(String catflag) {
        this.catflag = catflag == null ? null : catflag.trim();
    }

    public boolean modifyPartCategory(com.xujiakai.car.maintain.domain.dto.ProjcategoryDTO projcategory, String type) {
        boolean flag = false;
        if (projcategory != null) {
            try {
                if ("C".equals(type)) {// 添加信息
                    flag = daoFactory.getProjcategoryMapper().insertSelective(projcategory) > 0;
                } else if ("U".equals(type)) {
                    flag = daoFactory.getProjcategoryMapper().updateByPrimaryKeySelective(projcategory) > 0;
                } else if ("D".equals(type)) {
                    com.xujiakai.car.maintain.domain.dto.ProjcategoryDTO pg = daoFactory.getProjcategoryMapper().selectByPrimaryKey(projcategory.getId());
                    if (pg != null) {
                        pg.setCatflag(projcategory.getCatflag());
                        flag = daoFactory.getProjcategoryMapper().updateByPrimaryKeySelective(projcategory) > 0;
                    }
                }
            } catch (Exception e) {
                BaseDataManageService.logger.error("修改维修项目类别的信息失败!");
            }
        }
        return flag;
    }
}